package com.connector.server.service;

import org.slf4j.LoggerFactory;
import java.util.Iterator;
import com.connector.base.connection.impl.NettyConnection;
import com.google.common.collect.Lists;
import io.netty.channel.ChannelId;
import com.connector.base.protocol.Packet;
import java.util.List;
import com.connector.base.connection.Connection;
import com.connector.base.connection.channel.SocketChannel;
import java.util.concurrent.ConcurrentMap;
import com.connector.base.connection.impl.LocalConnectionRegistry;
import com.connector.server.jmx.JmxMessageBean;
import org.slf4j.Logger;

@Deprecated
public class PushMessageServiceHandler implements MessageServiceHandler
{
    private static final Logger log;

    @Override
    public void handler(final JmxMessageBean jmxMessageBean) {
        PushMessageServiceHandler.log.info("开始使用pushMessageServiceHandler推送消息.......");
        final ConcurrentMap<SocketChannel, Connection> cons =  LocalConnectionRegistry.getConnections();
    }

    public static void sendMsg(final List<String> userIds, final Packet packet, final ConcurrentMap<ChannelId, Connection> allConnection) {
        final List<Connection> connections = Lists.newArrayList();
        for (final Connection c : allConnection.values()) {
            final NettyConnection conn = (NettyConnection)c;
            for (final String userId : userIds) {
                final String uId = conn.getSessionContext().getUserId();
                if (userId.equals(uId)) {
                    PushMessageServiceHandler.log.info("给{}发送聊天消息", (Object)userId);
                    connections.add((Connection)conn);
                }
            }
        }
        for (final Connection connection : connections) {
            connection.channelSend((Object)packet);
        }
    }

    static {
        log = LoggerFactory.getLogger((Class)PushMessageServiceHandler.class);
    }
}
